jQuery(document).ready(function() {

	jQuery('#Listing').find('tr').first().nextAll().hover(
	function() {
		jQuery(this).find('td').addClass('current_row');
	},
	function() {
		jQuery(this).find('td').removeClass('current_row');
	});
});

function saveNews() {

	var newsTitle = jQuery.trim(jQuery('#news_title').val());
	if (newsTitle.length <= 0) {
		alert('新闻标题不能为空!');
		return false;
	}

	var newsCategoryId = jQuery('#category_id').val();
	var newsId = jQuery('#news_id').val();

	var editor = FCKeditorAPI.GetInstance('news_content');
	var newsContent = editor.GetXHTML(true);

	if (newsContent.length <= 0) {
		alert('新闻内容不能为空!');
		return false;
	}

	var params = new Object();
	params['act'] = 'save_news';
	params['news_id'] = newsId;
	params['news_title'] = newsTitle;
	params['category_id'] = newsCategoryId;
	params['news_content'] = newsContent;

	var _url = getCurrentUrl() + '?requestid=' + Math.random(10000);
	jQuery.ajax({
		url: _url,
		data: params,
		type: 'post',
		dataType: 'text',
		success: function(result) {
			if (result && result > 0) {
				alert('保存成功!');
				location.href = _url;
			} else {
				alert('保存失败!');
			}
		}
	});

}

function deleteNews(newsId) {
	if (!newsId) {
		alert('操作错误!');
		return false;
	}

	var t = window.confirm('确定删除此新闻?');
	if (!t) return false;

	var params = new Object();
	params['act'] = 'delete_news';
	params['news_id'] = newsId;

	var _url = getCurrentUrl() + '?requestid=' + Math.random(10000);
	jQuery.ajax({
		url: _url,
		data: params,
		dataType: 'text',
		success: function(result) {
			if (result && result > 0) {
				alert('删除成功!');
				location.href = _url;
			} else {
				alert('删除失败!');
			}
		}
	});

}

function getCurrentUrl() {
	return location.href.lastIndexOf("?") == - 1 ? location.href.substring((location.href.lastIndexOf("/")) + 1) : location.href.substring((location.href.lastIndexOf("/")) + 1, location.href.lastIndexOf("?"));
}

